using Godot;
using System;

[Tool]
public partial class TrackBlock : Area2D
{
    private const float BlockWidth = 10;

    [Export]
    public double DurationSecond = 1;

    [Export]
    public Color Background = Colors.White;

    public int TrackId = 0;

    public double StartTimeSecond = 0;

    public bool IsCompleted;

    private float _blockHeight = 10;

    // Called when the node enters the scene tree for the first time.
    public override void _Ready()
    {
        var unitMetric = GlobalData.UnitMetric;
        _blockHeight = (float)(unitMetric * DurationSecond);

        var blockWidth = BlockWidth;
        var blockHeight = _blockHeight;

        var collShape = GetNode<CollisionShape2D>(@"CollisionShape");
        collShape.Shape = new RectangleShape2D()
        {
            Size = new Vector2(blockWidth, blockHeight)
        };
    }

    // Called every frame. 'delta' is the elapsed time since the previous frame.
    //public override void _Process(double delta)
    //{
    //    var unitMetric = GlobalData.UnitMetric;
    //    _blockHeight = (float)(unitMetric * DurationSecond);
    //}
   
    public override void _Draw()
    {
        base._Draw();

        var blockWidth = BlockWidth;
        var blockHeight = _blockHeight;

        DrawRect(new Rect2(new Vector2(-blockWidth / 2, -blockHeight / 2), new Vector2(blockWidth, blockHeight)), Background);

    }
}
